// This file is part of WifiCC3000 - the Managed Wifi Driver for the TI CC3000
// WifiCC3000 is free software licensed under the Apache License 2.0
// by Valkyrie-MT

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace Networking
{
    internal class Response
    {
        public byte[] Payload { get; set; }

        internal Response(byte[] rawPayload)
        {
            Payload = rawPayload;

            //Debugger.VerbosePrint("test " + Extensions.GetName(typeof(HciCommand), this.Opcode));
            recTime = PowerState.Uptime;

            Debugger.VerbosePrint("New Event: OpCode: " + ((short)this.Opcode).ToHexString());
        }

        private TimeSpan recTime = TimeSpan.MinValue;

        public TimeSpan ReceiveTime
        {
            get { return recTime; }
        }

        internal HciCommand Opcode
        {
            get 
            { 
                try
                {
                    return (Payload != null && Payload.Length >= 3) ? ((HciCommand)(ushort)((Payload[2] << 8) | Payload[1])) : HciCommand.UNKNOWN; 
                }
                catch 
                {
                    return HciCommand.UNKNOWN;
                }
            }
        }

        public override string ToString()
        {
            return base.ToString();
        }

    }
}
